Skip to content

Add keyboard shortcuts panel#595

Merged
tracygardner merged 13 commits into
flipcomputing:mainfrom
lawsie:document-kb-shortcuts
Apr 30, 2026
Merged

Add keyboard shortcuts panel#595
tracygardner merged 13 commits into
flipcomputing:mainfrom
lawsie:document-kb-shortcuts

Conversation

@lawsie
Copy link
Copy Markdown
Contributor

@lawsie lawsie commented Apr 30, 2026

Summary

Adds a keyboard shortcuts panel which can be docked left or right.

image

Details

  • Press Ctrl + / or ⌘ + / to toggle open or close shortcut panel - it deliberately does NOT hide on Esc as you might be using Esc for something on the UI
  • Press Ctrl + Left arrow or Ctrl + Right arrow to dock it left or right
  • Press Ctrl + Up arrow or Ctrl + Down arrow to scroll up or down
  • Shortcuts should correctly display Ctrl on Windows and ⌘ if you're on Mac (Label keyboard controls based on platform #538 )
  • (As an aside, fixed a couple of implemented shortcuts that were Win only)

Further work to do

  • Translations for almost all strings need to be applied (once finalised)
  • Could implement the slide in/out feature Makecode has (but actually it's trivial to keyboard open/close it so maybe not)
  • It looks naff on mobile, but then again it's not relevant and you can't actually open it on mobile so...
  • Need to add link to keyboard controls documentation on hub from in-tool documentation

Relates to #512 #343

AI usage

Claude Sonnet 4.6 used throughout, with all changes carefully approved by a human.

Summary by CodeRabbit

  • New Features
    • Keyboard shortcuts panel now displays in a dedicated modal window (open/close with Ctrl+/)
    • Navigate the panel with arrow keys; use Escape to close
    • Enhanced keyboard support for Mac users with Meta key recognition and Cmd+Z/Cmd+Shift+Z shortcuts for Undo/Redo

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@lawsie has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 30 minutes and 19 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f206e9f4-b3be-40d1-b150-fc2865858c5e

📥 Commits

Reviewing files that changed from the base of the PR and between 63ed57a and 60fd799.

📒 Files selected for processing (3)
  • main/accessibility.js
  • style.css
  • ui/axis-keyboard.js
📝 Walkthrough

Walkthrough

The PR refactors keyboard shortcuts documentation from an inline sidebar element to a separate modal panel. It removes the keyboard controls UI from index.html's info-panel, creates a new ShortcutsPanel feature in accessibility.js that renders a dynamic modal with categorized shortcuts, updates main.js to trigger this panel via Ctrl+/, adds Mac support via Meta key handling across keyboard shortcuts, and styles the new modal interface.

Changes

Cohort / File(s) Summary
UI Panel Refactoring
index.html, style.css, main/accessibility.js, main/main.js
Moves keyboard shortcuts from static sidebar info-panel to a new ShortcutsPanel modal with platform-aware shortcut formatting, show/hide/toggle state management, arrow-key navigation, dock-position support, and close-button handling. New CSS styling configures the modal layout, kbd element styling, and overlay behavior.
Keyboard Shortcut Handling
main/blockhandling.js, main/input.js
Adds Meta key (Mac Command) support alongside Ctrl for block actions (. and ]) and canvas undo/redo (Ctrl/Meta+Z for undo, Ctrl/Meta+Shift+Z or Ctrl+Y for redo).
Keyboard Event Filtering
ui/axis-keyboard.js
Removes exclusion of #info-details element from keyboard event capture and reformats text-input detection logic.

Sequence Diagram

sequenceDiagram
    actor User
    participant Main as main.js
    participant ShortcutsPanel
    participant DOM
    
    User->>Main: Press Ctrl+/
    Main->>ShortcutsPanel: toggle()
    ShortcutsPanel->>ShortcutsPanel: Check if visible
    alt Panel hidden
        ShortcutsPanel->>DOM: Render shortcuts table<br/>(categorized rows)
        ShortcutsPanel->>DOM: Set display: visible
        ShortcutsPanel->>DOM: Add global click/key listeners
    else Panel visible
        ShortcutsPanel->>DOM: Set display: hidden
        ShortcutsPanel->>DOM: Remove global listeners
    end
    
    User->>DOM: Click close button or<br/>press Escape
    DOM->>ShortcutsPanel: Trigger hide()
    ShortcutsPanel->>DOM: Set display: hidden
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Add keyboard shortcuts for gizmo menu #591: Adds keyboard-shortcut overlay manager (GizmoMenuManager) in main/accessibility.js with similar modal/event-handling patterns to the new ShortcutsPanel feature.
  • Improve area menu #590: Modifies main/accessibility.js export patterns and main/main.js import strategy, directly overlapping with this PR's refactoring of the accessibility module integration.

Suggested labels

codex

Poem

🐰 A shortcuts panel pops to view,
Modal magic, fresh and new!
Mac and keyboard, side by side,
Arrow keys and scroll with pride!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add keyboard shortcuts panel' directly and clearly summarizes the main change—introducing a new keyboard shortcuts panel feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 30 minutes and 19 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@main/accessibility.js`:
- Around line 373-392: When opening the shortcuts panel in show(), capture and
save the currently focused element (e.g. this._previousFocus =
document.activeElement), set focus into the panel (preferably to its close
button or first focusable element inside this.panel; add tabindex="-1" if
needed) and ensure the panel is focusable so keyboard users can tab the
contents; in hide(), restore focus to this._previousFocus (and clear the saved
reference) before hiding the panel. Update the show() and hide() methods on the
same object (references: show(), hide(), this.panel, and the panel’s close
button element) so focus is moved into .shortcuts-panel on open and returned on
close.
- Around line 408-431: The keydown listener on document currently traps all
Ctrl/Cmd+Arrow events even when focus is in editable fields; update the handler
(the document.addEventListener("keydown"...) that references this.panel and
calls this.setDock) to first ignore events when focus is outside the shortcuts
panel or when the event target is an editable control: bail out unless
this.panel.contains(document.activeElement) OR (event.target is inside the
panel). Also treat inputs, textareas, contentEditable elements and selects as
editable by checking tagName and el.isContentEditable (or using
event.target.closest to test), and only run the ArrowLeft/Right/Up/Down handling
when the focus/target is within the shortcuts panel.

In `@style.css`:
- Around line 1595-1599: The CSS rule for the kbd selector uses the keyword
"currentColor" with mixed case and triggers Stylelint's value-keyword-case;
update the property value in the kbd rule (border: 1px solid currentColor) to
the lowercase form "currentcolor" so it satisfies the linter. Locate the kbd
selector in style.css and replace the currentColor token used in border
declarations with currentcolor, keeping the rest of the declaration intact.

In `@ui/axis-keyboard.js`:
- Around line 17-26: The gizmo key handler currently short-circuits when the
event target t is inside "#codePanel" or "header" but doesn't exclude the
shortcuts panel; update the conditional that checks t?.closest (or add an
additional early-return) to also return when t.closest(".shortcuts-panel") is
true so keyboard interactions inside the shortcuts panel don't propagate to
gizmo handling; ensure you modify the selector used around t?.closest (or add a
separate check immediately before the tag/isContentEditable checks) in
ui/axis-keyboard.js so Enter and Ctrl/Cmd+Arrow keys inside the shortcuts panel
are not swallowed by the gizmo handler.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04263898-0ccc-47bd-afa3-767cc7beae83

📥 Commits

Reviewing files that changed from the base of the PR and between c5fce28 and 63ed57a.

📒 Files selected for processing (7)
  • index.html
  • main/accessibility.js
  • main/blockhandling.js
  • main/input.js
  • main/main.js
  • style.css
  • ui/axis-keyboard.js

Comment thread main/accessibility.js
Comment thread main/accessibility.js
Comment thread style.css
Comment thread ui/axis-keyboard.js Outdated
@tracygardner tracygardner merged commit 43d5784 into flipcomputing:main Apr 30, 2026
5 checks passed
@lawsie lawsie mentioned this pull request May 6, 2026
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants